package interceptor01.demo.controller;

import interceptor01.demo.ApiResponse;
import interceptor01.demo.enums.ResponseCode;
import interceptor01.demo.exception.CustomerException;
import interceptor01.demo.po.ResultPo;
import interceptor01.demo.po.UserInfoPo;
import interceptor01.demo.po.UserThreadLocal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {

    @PostMapping("/test")
    public ResultPo test() {
        UserInfoPo userInfoPo = UserThreadLocal.get();
        ResultPo resultPo = new ResultPo();
        resultPo.setData(userInfoPo);
        resultPo.setCode(200);
        resultPo.setMsg("请求成功");
        return resultPo;
    }


    @PostMapping("/test1")
    public ApiResponse<String> test1() {
        return ApiResponse.success("请求成功");
    }

    @GetMapping("/test2")
    public ApiResponse<String> test2(){
        throw new CustomerException(ResponseCode.USERNAME_OR_PASSWORD_ERROR.getCode(), ResponseCode.USERNAME_OR_PASSWORD_ERROR.getMessage());
    }
}
